////////////////////////////////////////////////////////////////////////////////
/// Midnight Circus 2007
////////////////////////////////////////////////////////////////////////////////

namespace GatherTogether
{
    namespace GatherDrops
    {
        /// <summary>
        /// Class that contains information about the possible items aquired from
        /// various resource node harvests.
        /// </summary>
        class GatherDropsDB : System.Collections.Generic.IEnumerable<Node>
        {
            protected System.Collections.Hashtable m_nodes = new System.Collections.Hashtable();

            public int Count
            {
                get
                {
                    return m_nodes.Count;
                }
            }

            public System.Collections.Generic.IEnumerator<Node> GetEnumerator()
            {
                foreach (System.Collections.DictionaryEntry entry in m_nodes)
                {
                    yield return entry.Value as Node;
                }
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            public void AddNode(Node node)
            {
                Node myNode = m_nodes[node.Id] as Node;

                // check to see if a node with this id already exists
                if (myNode == null)
                {
                    // it does not, so add a new entry to the table
                    m_nodes.Add(node.Id, node);
                }
                else
                {
                    // it does, so we need to update all of its loots
                    foreach (Loot otherLoot in node)
                    {
                        myNode.AddLoot(otherLoot);
                    }
                }
            }
        }
    }
}
